package lcr;

public class Test0090 {
}

class Solution0090_1 {
    public int rob(int[] nums) {
        int length = nums.length;
        if (length<2) return nums[0];

        int pre1=0,pre2=0;
        for (int i = 0; i < length-1; i++) {
            int temp = pre2;
            pre2=Math.max(pre1+nums[i],pre2);
            pre1=temp;
        }
        int ans1 = pre2;

        pre1=0;
        pre2=0;
        for (int i = 1; i < length; i++) {
            int temp = pre2;
            pre2=Math.max(pre1+nums[i],pre2);
            pre1=temp;
        }
        return Math.max(ans1,pre2);
    }
}
